<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>编辑资源</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>js/bootstrap-3.3.6/dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrapValidator.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mydialog.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css" />
  </head>
  <body>
  	<div class="col-sm-10 ">
	  	<form id="form" class="form-horizontal">
	  	   <input type="hidden" name="id" value="${resource.id }">
	       <div class="panel panel-default">
	         <div class="panel-heading">
	           <h4 class="panel-title">编辑资源</h4>
	         </div>
	         <div class="panel-body">
	           <div class="form-group">
	             <label class="col-sm-2 control-label">名称:</label>
	             <div class="col-sm-6">
	               <input type="text" name="name" class="form-control" value="${resource.name }">
	             </div>
	           </div>
	           
	           <div class="form-group">
	             <label class="col-sm-2 control-label">url:</label>
	             <div class="col-sm-6">
	               <input type="text" name="url" class="form-control"  value="${resource.url }">
	             </div>
	           </div>
	           <div class="form-group">
	             <label class="col-sm-2 control-label">类型:</label>
	             <div class="col-sm-6">
	               <input type="text" name="type" class="form-control"  value="${resource.type }">
	             </div>
	           </div>
	           <div class="form-group">
	             <label class="col-sm-2 control-label">级别:</label>
	             <div class="col-sm-6">
	               <input type="text" name="level" class="form-control"   value="${resource.level }">
	             </div>
	           </div>
	            <div class="form-group">
	             <label class="col-sm-2 control-label">状态:</label>
	             <div class="col-sm-6">
	               <select class="form-control input-sm mb15" name="isUsed">
	                  <option value="1" selected="selected">可用</option>
	                  <option value="0">不可用</option>
	                </select>
	             </div>
	           </div>
	            <div class="form-group">
	             <label class="col-sm-2 control-label">父id:</label>
	             <div class="col-sm-6">
	               <input type="text" name="parentId" class="form-control"  value="${resource.parentId }">
	             </div>
	           </div>
	            <div class="form-group">
	             <label class="col-sm-2 control-label">资源path:</label>
	             <div class="col-sm-6">
	               <input type="text" name="path" class="form-control"  value="${resource.path }">
	             </div>
	           </div>
	            <div class="form-group">
	             <label class="col-sm-2 control-label">备注:</label>
	             <div class="col-sm-6">
	               <input type="text" name="comment" class="form-control"   value="${resource.comment }">
	             </div>
	           </div>
	         </div>
	         <div class="panel-footer">
	           <button class="btn btn-primary" id="editResourceBtn">保存</button>
	           <button type="reset" class="btn btn-default">重置</button>
	         </div>
	       </div>
	     </form>
     </div>
  </body>
  <script type="text/javascript" src="<%=basePath%>js/jquery-1.9.1.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="<%=basePath%>js/bootstrap-3.3.6/dist/js/bootstrap.min.js" charset="utf-8"></script>
  <script type="text/javascript">
		$(document).ready(function(){
			$('#defaultForm').bootstrapValidator({
	            message: 'This value is not valid',
	            feedbackIcons: {
	                valid: 'glyphicon glyphicon-ok',
	                invalid: 'glyphicon glyphicon-remove',
	                validating: 'glyphicon glyphicon-refresh'
	            },
	            fields: {
	                name: {
	                    validators: {
	                        notEmpty: {},
	                        stringLength: {min: 1,max: 30},
	                    }
	                },
	                url: {
	                    validators: {
	                        notEmpty: {}
	                    }
	                },
	                type: {
	                    validators: {
	                        notEmpty: {}
	                    }
	                },
	                comment: {
	                    validators: {
	                        notEmpty: {}
	                    }
	                }, 
	            }
	        }).on('success.form.bv', function(e) {
	            // Prevent form submission
	            e.preventDefault();

	            // Get the form instance
	            var $form = $(e.target);

	            // Get the BootstrapValidator instance
	            var bv = $form.data('bootstrapValidator');

	            // Use Ajax to submit form data
	            $.post($form.attr('action'), $form.serialize(), function(result) {
	            	if(result.message != undefined){
			            	var grayScreen=document.getElementById("gray-screen"); 
			            	Dialog({
					                "msg": '<div class="D_alert">'+result.message+'</div>',
					                "title": "提示",
					                "showButtons": true,
					                "cancelButton": false,
					                "onComplete": function() {
					                 	$("body").empty();
					                	window.location.reload();
					                }
					            });	
	            	}else{
	            		window.location.reload();
	            }, 'json');
	        });
		});
    </script>
</html>
